package com.example.infowall02.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class EmailService {
    // 注入JavaMailSender
    @Autowired
    private JavaMailSender mailSender;
    @Value("${spring.mail.username}")
    private String fromEmail;
    // 发送邮箱验证码
    public void sendVerificationCode(String toEmail, String verificationCode) {
        // 构建邮件消息
        SimpleMailMessage message = new SimpleMailMessage();
        // 邮件内容
        log.info("00000000000"+fromEmail);
        message.setFrom(fromEmail);
        // 邮件主题
        message.setTo(toEmail);
        // 邮件主题
        message.setSubject("infowall管理员邮箱验证码");
        // 邮件内容
        message.setText("Your verification code is: " + verificationCode+"，有效时间为5分钟");
        // 发送邮件
        mailSender.send(message);
    }
}

